package com.raining.inningz.ui.play;

import java.util.List;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;


import com.raining.inningz.R;
import com.raining.inningz.adapter.MatchListAdapter;
import com.raining.inningz.baseclass.BaseFragment;
import com.raining.inningz.constants.IFragmentNameConstants;
import com.raining.inningz.constants.IParamConstants;
import com.raining.inningz.custom.animation.AnimationFactory;
import com.raining.inningz.custom.animation.AnimationFactory.FlipDirection;
import com.raining.inningz.database.dao.Matches;

public class PlayTeamRosterFragment  extends BaseFragment implements OnClickListener{
	
	
	private LayoutInflater mInflater;
	private View view;
	
	
	private ViewFlipper viewFlipper;
	
	
	private PlayAddPlayerFragment playAddPlayerFragment;
	
	private View viewVisitingTeam;
	private View viewHostingTeam;
	
	private Button btnShowOpponentVisitingTeam;
	private Button btnShowOpponentHostingTeam;
	
	
	private TextView txtAddPlayerVisitingTeam;
	private TextView txtAddPlayerHostingTeam;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		if(getArguments()!=null){
			
			
			matchID=getArguments().getString(IParamConstants.MATCH_ID);
			
			isEdit=getArguments().getBoolean(IParamConstants.IS_EDIT);
			}
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mInflater = inflater;
		
		view = inflater.inflate(R.layout.fragment_play_team_roster, container, false);
		context = mInflater.getContext();

		initialiseUI();
		
		setData();
		
		setListner();

		return view;
	}

	

	



	private void initialiseUI() {
		
		setHeaderIntialize(view);
		setHeaderTitle(resources.getString(R.string.inningz),Color.BLACK);
		setLeftTextSelector(resources.getColor(R.color.top_bar_Button),
				resources.getColor(R.color.top_bar_Button_press), "InningZ");
		setRightTextSelector(resources.getColor(R.color.top_bar_Button),
				resources.getColor(R.color.top_bar_Button_press), "Save");
		setHeaderTitle(resources.getString(R.string.about), Color.BLACK);
	
		
		viewFlipper=(ViewFlipper)view.findViewById(R.id.viewFlipper);
		
		
		
		
		viewVisitingTeam = (View)view.findViewById(R.id.viewVisitingTeam);
		viewHostingTeam = (View)view.findViewById(R.id.viewHostingTeam);
		
		btnShowOpponentVisitingTeam=(Button)viewVisitingTeam.findViewById(R.id.btnShowOpponent);
		btnShowOpponentHostingTeam=(Button)viewHostingTeam.findViewById(R.id.btnShowOpponent);
		
		
		txtAddPlayerVisitingTeam=(TextView)viewVisitingTeam.findViewById(R.id.txtAddPlayer);
		txtAddPlayerHostingTeam=(TextView)viewHostingTeam.findViewById(R.id.txtAddPlayer);
	}
	
	private void setData() {
	
	
		
		
	}
	private void setListner() {
		
		
		
		btnShowOpponentVisitingTeam.setOnClickListener(this);
		btnShowOpponentHostingTeam.setOnClickListener(this);
		
		
		txtAddPlayerVisitingTeam.setOnClickListener(this);
		txtAddPlayerHostingTeam.setOnClickListener(this);
		
	}



	@Override
	public void onClick(View v) {
		
		if(v==btnShowOpponentHostingTeam){
			AnimationFactory.flipTransition(viewFlipper, FlipDirection.LEFT_RIGHT);
		}
		else if(v==btnShowOpponentVisitingTeam){
			AnimationFactory.flipTransition(viewFlipper, FlipDirection.LEFT_RIGHT);
		}
		else if(v==txtAddPlayerVisitingTeam){
			
			
			
			Bundle args = new Bundle();
			args.putString(IParamConstants.MATCH_ID, matchID);
			args.putBoolean(IParamConstants.IS_EDIT, true);
			playAddPlayerFragment=new PlayAddPlayerFragment();
			
			playAddPlayerFragment.setArguments(args);
			changeFragment(playAddPlayerFragment, IFragmentNameConstants.PLAY_ADD_PLAYERS);
			
		}
		else if(v==txtAddPlayerHostingTeam){
			
			Bundle args = new Bundle();
			args.putString(IParamConstants.MATCH_ID, matchID);
			args.putBoolean(IParamConstants.IS_EDIT, true);
			playAddPlayerFragment=new PlayAddPlayerFragment();
			
			playAddPlayerFragment.setArguments(args);
			changeFragment(playAddPlayerFragment, IFragmentNameConstants.PLAY_ADD_PLAYERS);
			
		}
	}

}
